package com.hdcircles.autoform.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.hdcircles.autoform.app.App;
import com.hdcircles.autoform.app.Constants;

/**
 * Created by hdcircles on 2016/9/23.
 */

public class SharedPreferenceUtil {

    private static final boolean DEFAULT_NIGHT_MODE=false;
    private static final boolean DEFAULT_NO_IMAGE=false;
    private static final boolean DEFAULT_AUTO_SAVE=true;
    private static final boolean DEFAULT_LIKE_POINT=false;
    private static final int DEFAULT_CURRENT_ITEM=Constants.TYPE_LABEL;
    private static final boolean DEFAULT_DATA_STATE=false;
    private static final String SHAREPREFERENCE_NAME="my_sp";

    public static SharedPreferences getAppSp(){
        return App.getInstance().getSharedPreferences(SHAREPREFERENCE_NAME, Context.MODE_PRIVATE);
    }

    public static boolean getNightModeState(){
        return getAppSp().getBoolean(Constants.SP_NIGHT_MODE,DEFAULT_NIGHT_MODE);
    }

    public static boolean setNightModeState(boolean state){
        return getAppSp().edit().putBoolean(Constants.SP_NIGHT_MODE,state).commit();
    }

    public static boolean getDefaultDataState(){
        return getAppSp().getBoolean(Constants.SP_DEFAULT_DATA,DEFAULT_DATA_STATE);
    }

    public static boolean setDefaultDataState(boolean state){
        return getAppSp().edit().putBoolean(Constants.SP_DEFAULT_DATA,state).commit();
    }

    public static boolean getAutoCacheState(){
        return getAppSp().getBoolean(Constants.SP_AUTO_CACHE,DEFAULT_AUTO_SAVE);
    }

    public static boolean setAutoCacheState(boolean state){
        return getAppSp().edit().putBoolean(Constants.SP_AUTO_CACHE,state).commit();
    }

    public static int getCurrentItem(){
        return getAppSp().getInt(Constants.SP_CURRENT_ITEM,DEFAULT_CURRENT_ITEM);
    }

    public static void setCurrentItem(int item){
        getAppSp().edit().putInt(Constants.SP_CURRENT_ITEM,item).apply();
    }

    public static String getUserEmail(){
        return getAppSp().getString(Constants.SP_USER,"");
    }

    public static void setUserEmail(String email){
        getAppSp().edit().putString(Constants.SP_USER,email).apply();
    }

    public static void setUserName(String name){
        getAppSp().edit().putString(Constants.SP_USER_NAME,name).apply();
    }

    public static String getUserName(){
        return getAppSp().getString(Constants.SP_USER_NAME,"");
    }

}
